package com.cat.dynamicPlanning;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/house-robber/description/
 * @create 2025/8/27 15:11
 * @since JDK17
 */

public class Solution11 {
    public int rob(int[] nums) {
        if (nums.length == 1) {
            return nums[0];
        }
        int n = nums.length;
        int[] dp = new int[n];
        dp[0] = nums[0];
        dp[1] = Math.max(nums[0], nums[1]);
        for (int i = 2; i < n; i++) {
            if (dp[i - 1] > dp[i - 2] + nums[i]) {
                dp[i] = dp[i - 1];
            } else {
                dp[i] = nums[i] + dp[i - 2];
            }
        }
        return Math.max(dp[n - 1], dp[n - 2]);
    }
}
